//
//  YTGiftView.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/19.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTGiftView.h"
@interface YTGiftView ()
@property (weak, nonatomic) IBOutlet UIView *contentView;

@end
@implementation YTGiftView

// 实例化
+ (instancetype)giftViewWithFrame:(CGRect)frame
{
    UINib *nib = [UINib nibWithNibName:@"YTGiftView" bundle:nil];
    YTGiftView *view = [nib instantiateWithOwner:nil options:nil][0];
    view.frame = frame;
    return view;
}
- (IBAction)openButtonClick:(UIButton *)sender
{
    NSAssert(self.openClickBlock != nil, @"openClickBlock 不能为nil");
    
    [self dismissView];
    self.openClickBlock();
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.contentView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissView)];
    [self addGestureRecognizer:tap];
}

- (void)dismissView
{
    [UIView animateWithDuration:0.25 animations:^{
        self.alpha = 0;
        self.closeBlock();
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
   
}

@end
